#pragma once

#include <QObject>
#include <QMutex>
#include <QThread>
#include <QWaitCondition>
#include <QQueue>
#include <QDir>
#include <QDateTime>
#include <QStandardPaths>
#include <QTextCodec>
#include <QRegularExpression>
#include <QCryptographicHash>
#include <QFileInfo>
#include <QThread>
#include <QDebug>
#include <QUuid>
#include <QCoreApplication>
#include "../dao/noveldao.h"
#include "../dao/chapterdao.h"
#include "../entity/novelinfo.h"
#include "../entity/chapterinfo.h"
#include "../utils/md5utils.h"
#include "novelparseworker.h"

// 章节解析任务优先级
enum ChapterParsePriority {
    LowPriority = 0,    // 后台解析
    HighPriority = 1     // 用户阅读优先级
};

class NovelService : public QObject {
    Q_OBJECT
public:
    explicit NovelService(QObject *parent = nullptr);

    virtual ~NovelService() override;

    // 获取所有的小说
    Q_INVOKABLE QList<QObject *> getAllNovels();

    // 导入小说
    Q_INVOKABLE void importFromPath(const QString &path);

    //查询对应小说的所有章节
    Q_INVOKABLE QList<QObject *> getChaptersByNovelId(const QString &novelId);

signals:
        //导入成功信号
        void novelImported(const QString &novelName);

        //导入失败信号
        void importError(const QString &errorMessage);

private:
    // 解析小说基本信息
    NovelInfo *parseNovelBasicInfo(const QString &filePath);

private:
    NovelDao *m_novel_dao;
    ChapterDao *m_chapter_dao;
};
